﻿using IBLL;
using IBLL.Dto;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class RoomTypeBLL : IRoomTypeBLL
    {
        public RoomTypeBLL(IBase<RoomType> db)
        {
            Db = db;
        }

        public IBase<RoomType> Db { get; }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t">参数</param>
        /// <returns>返回</returns>
        public Task<int> AddAsync(RoomType t)
        {
           return Db.AddAsync(t);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>返回</returns>
        public Task<int> DeleteLogiceAsync(int id)
        {
            var m = Db.GetValue(id);
            m.IsDelete = true;
            return Db.UpdateAsync(m);
        }
        /// <summary>
        /// 查全部
        /// </summary>
        /// <returns>返回</returns>
        /// <exception cref="NotImplementedException"></exception>
        public IQueryable<RoomType> GetRoomsAll()
        {
            return Db.GetAll();
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="index">当前页</param>
        /// <param name="size">总条数</param>
        /// <param name="name">名称</param>
        /// <returns>返回</returns>
        public RoomTypePageDto GetRoomTypePage(int index, int size, string? name)
        {
            var n = Db.GetAll();
            if (!string.IsNullOrEmpty(name)) 
            {
                n = n.Where(x => x.Name.Contains(name));
            }
            var c = n.Count();
            var d=n.OrderBy(x=>x.Id).Skip((index-1)*size).Take(size).ToList();
            RoomTypePageDto dto = new RoomTypePageDto();
            dto.Data = d;   
            dto.Count = c;
            return dto;
        }
    }
}
